#ifndef CSOCKET_H
#define CSOCKET_H

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
    
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#include <vector>
#include <fcntl.h>

using namespace std;

extern bool verbose_log; //verbose log of process() loops

class CSocket
{
    public:
            CSocket();
           ~CSocket();         

		   void write_test(int sock);
          
           int process(); //select() sockets and parses recevied data, sortof non blocking intended for main loop
           
           void init();
           bool newDataCheck();
           
           //returns and sets ref param to last data buffer stored in vector buffers
           unsigned char* getData(unsigned char* &buffer, int &len);
           
           int sendData(unsigned char *buffer, int len);
           
       //    virtual void parse(unsigned char *buffer, int len);
           
          
          // int (CSocket::*pt2Member)(float, char, char) = NULL; 
    private: 
            struct BUFFER_STRUCT
            {
              unsigned char *buffer;
              int len;
            };
            
            vector<BUFFER_STRUCT*> buffers;
            int buffers_count;
            bool data_avail; 
            bool data_new;
             
            int sock;
            int newfd;

            fd_set active_fd_set, read_fd_set;  
            struct timeval timeout;
            
            struct sockaddr_in name;
                     
            //functions
            int make_socket (uint16_t port);
            int read_from_client (int filedes);
};
#endif
